package com.lk.ii.controller;

import java.util.List;

import com.lk.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiSolution;
import com.lk.ii.service.IIiSolutionService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 解决方案Controller
 * 
 * @author lk
 * @date 2021-02-22
 */
@Controller
@RequestMapping("/ii/solution")
public class IiSolutionController extends BaseController
{
    private String prefix = "ii/solution";

    @Autowired
    private IIiSolutionService iiSolutionService;

    @RequiresPermissions("ii:solution:view")
    @GetMapping()
    public String solution()
    {
        return prefix + "/solution";
    }

    /**
     * 查询解决方案列表
     */
    @RequiresPermissions("ii:solution:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiSolution iiSolution)
    {
        startPage();
        List<IiSolution> list = iiSolutionService.selectIiSolutionList(iiSolution);
        return getDataTable(list);
    }

    /**
     * 导出解决方案列表
     */
    @RequiresPermissions("ii:solution:export")
    @Log(title = "解决方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiSolution iiSolution)
    {
        List<IiSolution> list = iiSolutionService.selectIiSolutionList(iiSolution);
        ExcelUtil<IiSolution> util = new ExcelUtil<IiSolution>(IiSolution.class);
        return util.exportExcel(list, "solution");
    }

    /**
     * 新增解决方案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存解决方案
     */
    @RequiresPermissions("ii:solution:add")
    @Log(title = "解决方案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiSolution iiSolution)
    {
        iiSolution.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(iiSolutionService.insertIiSolution(iiSolution));
    }

    /**
     * 修改解决方案
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IiSolution iiSolution = iiSolutionService.selectIiSolutionById(id);
        mmap.put("iiSolution", iiSolution);
        return prefix + "/edit";
    }

    /**
     * 修改保存解决方案
     */
    @RequiresPermissions("ii:solution:edit")
    @Log(title = "解决方案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiSolution iiSolution)
    {
        iiSolution.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(iiSolutionService.updateIiSolution(iiSolution));
    }

    /**
     * 删除解决方案
     */
    @RequiresPermissions("ii:solution:remove")
    @Log(title = "解决方案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiSolutionService.deleteIiSolutionByIds(ids));
    }
}
